﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CashShop.AccessDataLib;
using CashShop.Bussiness;

namespace CashShop
{
    public partial class Form1 : Form
    {
        private CashFacade cf = new CashFacade();
        //用于计算总价
        private decimal totalPrice = 0.00m;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //读取xml文件  绑定下拉菜单
            cbxType.DataSource = cf.GetCashAcceptTypeList();
            cbxType.SelectedIndex = 0;
        }

        private void cobType_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void cbxType_Format(object sender, ListControlConvertEventArgs e)
        {

        }

        private void btnComfirm_Click(object sender, EventArgs e)
        {
            var total = 0.00M;
            //传值下拉选择活动和原价，计算实际收费
            total = cf.GetTotalPrice(cbxType.SelectedItem.ToString(),
            Convert.ToDecimal(txtPrice.Text) * Convert.ToDecimal(txtCount.Text));

            totalPrice += total;
            lbList.Items.Add("单价：" + txtPrice.Text + "  数量：" + txtCount.Text + "  " + cbxType.SelectedItem + "  合计：" +
                             total.ToString("C"));

            lbTotalPrice.Text = totalPrice.ToString("C");
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            totalPrice = 0.00m;
            txtCount.Text = ""; 
            txtPrice.Text = "";
            lbList.Items.Clear();
            cbxType.SelectedIndex = 0;
            lbTotalPrice.Text ="¥0.00";

        }

        private void txtPrice_KeyPress(object sender, KeyPressEventArgs e)
        {

            if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (Char)8)
            {
               e.Handled = true;
            }
        }

        private void txtCount_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (Char)8)
            {
                e.Handled = true; 
            }
        }
    }
}
